# 1、导包
import time

from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.support.wait import WebDriverWait

# 2、实例化浏览器对象
driver_path = "C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/geckodriver.exe"
service = Service(executable_path=driver_path)
driver = webdriver.Firefox(service=service)
driver.get("file:///E:/project/learn-python/html%E5%9F%BA%E7%A1%80/3-%E8%A1%A8%E5%8D%95%E6%8F%90%E4%BA%A4.html")

# 3、需求：
# ① 隐式等待：定位用户名输入框，并输入：admin1
'''
driver.implicitly_wait(10)
driver.find_element(By.ID, 'user').send_keys('admin1')
'''
# ② 显示等待：定位用户名输入框，并输入：admin2
element = WebDriverWait(driver, 10, poll_frequency=0.5).until(lambda x: x.find_element(By.ID, "user"))
element.send_keys('admin2')